package main

import (
	"fmt"
	"gee/gee"
	"net/http"
	"time"
)

var (
	data    *gee.CourseApi
	allData *gee.ResponseJson
)

var (
	username string
	password string
)

func ConfReload(username, password string) {
	fmt.Println("数据将在6小时后刷新...")
	ticker := time.NewTicker(6 * time.Hour)
	for {
		select {
		case <-ticker.C:
			data = gee.Api(username, password)
			allData = gee.API(username, password)
			fmt.Println("数据刷新成功。")
		}
	}
}

func Myjob(username, password string) {
	data = gee.Api(username, password)
	allData = gee.API(username, password)
	r := gee.New()
	r.Use(gee.Logger())
	r.GET("/", func(c *gee.Context) {
		c.JSON(http.StatusOK, data)
	})

	r.GET("/all", func(c *gee.Context) {
		c.JSON(http.StatusOK, allData)
	})

	err := r.Run(":8080")
	gee.CheckError(err)
}
func main() {
	go ConfReload(username, password)
	Myjob(username, password)
}

func init() {
	fmt.Print("请输入账号和密码:")
	fmt.Scanf("%s %s", &username, &password)
}
